1. Field of the Invention
The present invention relates to design and implementation of digital processing systems, and more specifically to a method and apparatus for providing optimal number of threads to applications performing multi-tasking using threads.
2. Related Art
Multi-tasking refers to execution of multiple tasks in parallel generally sharing the same resources (e.g., processing unit, memory). Multi-tasking provides several advantages such as enabling continuation of execution of other tasks when one task is blocked, for example, awaiting the occurrence of an external event.
Applications often perform multi-tasking using threads. As is well known, a thread generally refers to a sub-set of software instructions (of a program) which can be executed by a program (implementing the application). Threads are differentiated from processes in that each process generally independently executes a complete program. Threads generally offer advantages such as management (creation, destruction, etc.) with minimal overhead (compared to processes), and thus are widely used in several environments (e.g., Java).
Threads are often initiated (created) in anticipation of future requirement of execution of tasks (e.g., tasks that would support processing of a service request such as a sales order). Such prior initiation enables the tasks to be processed soon after arrival of service requests, thereby minimizing the response time to process the service requests.
It is generally desirable to provide an optimal number of threads to applications performing multi-tasking using threads. For example, providing fewer threads (than needed) could lead to degradation (high) response times since time would be consumed either to initiate additional threads, or to wait for a thread to be freed. On the other hand, initiating more threads would lead to unneeded overhead in creation and termination (destruction) of threads, as well as memory overhead.
In one prior embodiment, the number of threads provided to an application is determined based on static configuration according to a pre-specified convention (e.g., in a pre-specified file). Unfortunately, the application may need different number of threads at different points of time, and accordingly fewer or more threads (compared to an optimal number) may be provided, potentially leading to various undesirable results noted above.
Accordingly what is needed is a method and apparatus for providing optimal number of threads to applications performing multi-tasking using threads.
In the drawings, like reference numbers generally indicate identical, functionally similar, and/or structurally similar elements. The drawing in which an element first appears is indicated by the leftmost digit(s) in the corresponding reference number.